package pl.softech.engine3d.graphics;

import java.awt.Color;
import java.awt.Graphics2D;

import pl.softech.engine3d.math3d.SolidPolygon3D;
import pl.softech.engine3d.math3d.Transform3D;
import pl.softech.engine3d.math3d.ViewWindow;

/**
    Klasa SolidPolygonRenderer transformuje i rzutuje na ekran
    wielokąt wypełniony jednolitym kolorem.
*/
public class SolidPolygonRenderer extends PolygonRenderer {

    public SolidPolygonRenderer(Transform3D camera,
        ViewWindow viewWindow)
    {
        this(camera, viewWindow, true);
    }

    public SolidPolygonRenderer(Transform3D camera,
        ViewWindow viewWindow, boolean clearViewEveryFrame)
    {
        super(camera, viewWindow, clearViewEveryFrame);
    }


    protected void drawCurrentPolygon(Graphics2D g) {

        // ustaw kolor
        if (sourcePolygon instanceof SolidPolygon3D) {
            g.setColor(((SolidPolygon3D)sourcePolygon).getColor());
        }
        else {
            g.setColor(Color.GREEN);
        }

        // rysuj linie skanow
        int y = scanConverter.getTopBoundary();
        while (y<=scanConverter.getBottomBoundary()) {
            ScanConverter.Scan scan = scanConverter.getScan(y);
            if (scan.isValid()) {
                g.drawLine(scan.left, y, scan.right, y);
            }
            y++;
        }
    }
}
